$(function(){

    $("body").css("opacity","1")

    $("#xuefenxiuqu").click(function(){
        $(this).css({"background-color":"#007dd2","color":"white"})
        $("#jihuakecheng").css({"background-color":"white","color":"black"})
        $("#quanxiaotongxuan").css({"background-color":"white","color":"black"})
        $("#tiyuxiangmu").css({"background-color":"white","color":"black"})
        $("#waiyudengji").css({"background-color":"white","color":"black"})
        $("#xfxq").show(500)
        $("#jhkc").hide(500)
        $("#qxtx").hide(500)
        $("#tyxy").hide(500)
        $("#wydj").hide(500)
    });

    $("#jihuakecheng").click(function(){
        $(this).css({"background-color":"#007dd2","color":"white"})
        $("#xuefenxiuqu").css({"background-color":"white","color":"black"})
        $("#quanxiaotongxuan").css({"background-color":"white","color":"black"})
        $("#tiyuxiangmu").css({"background-color":"white","color":"black"})
        $("#waiyudengji").css({"background-color":"white","color":"black"})
        $("#xfxq").hide(500)
        $("#jhkc").show(500)
        $("#qxtx").hide(500)
        $("#tyxy").hide(500)
        $("#wydj").hide(500)
    });

    $("#quanxiaotongxuan").click(function(){
        $(this).css({"background-color":"#007dd2","color":"white"})
        $("#xuefenxiuqu").css({"background-color":"white","color":"black"})
        $("#jihuakecheng").css({"background-color":"white","color":"black"})
        $("#tiyuxiangmu").css({"background-color":"white","color":"black"})
        $("#waiyudengji").css({"background-color":"white","color":"black"})
        $("#xfxq").hide(500)
        $("#jhkc").hide(500)
        $("#qxtx").show(500)
        $("#tyxy").hide(500)
        $("#wydj").hide(500)
    });

    $("#tiyuxiangmu").click(function(){
        $(this).css({"background-color":"#007dd2","color":"white"})
        $("#xuefenxiuqu").css({"background-color":"white","color":"black"})
        $("#jihuakecheng").css({"background-color":"white","color":"black"})
        $("#quanxiaotongxuan").css({"background-color":"white","color":"black"})
        $("#waiyudengji").css({"background-color":"white","color":"black"})
        $("#xfxq").hide(500)
        $("#jhkc").hide(500)
        $("#qxtx").hide(500)
        $("#tyxy").show(500)
        $("#wydj").hide(500)
    });

    $("#waiyudengji").click(function(){
        $(this).css({"background-color":"#007dd2","color":"white"})
        $("#xuefenxiuqu").css({"background-color":"white","color":"black"})
        $("#jihuakecheng").css({"background-color":"white","color":"black"})
        $("#quanxiaotongxuan").css({"background-color":"white","color":"black"})
        $("#tiyuxiangmu").css({"background-color":"white","color":"black"})
        $("#xfxq").hide(500)
        $("#jhkc").hide(500)
        $("#qxtx").hide(500)
        $("#tyxy").hide(500)
        $("#wydj").show(500)
    });

    var username = localStorage.getItem("username");


    $.post("/xjxt/xuefen?username="+ username +"",function(res){

        var hehe = JSON.parse(res);
        console.log(hehe);
        $("#zongxue").html(hehe[0]["sum(xuefen)"]);
        $("#bixiu").html(hehe[1]["sum(xuefen)"]);
        $("#xuanxiu").html(hehe[2]["sum(xuefen)"]);
        $("#xuewei").html(hehe[3]["sum(xuefen)"]);
        $("#quanxiao").html(hehe[4]["sum(xuefen)"]);
        $("#tiyuke").html(hehe[5]["sum(xuefen)"]);
        $("#bujige").html(hehe[6]["sum(xuefen)"]);
        $("#pingjunjd").html(hehe[7]["sum(xuefen)"].slice(0,5));
        $("#bixiujd").html(hehe[8]["sum(xuefen)"].slice(0,5));
        $("#xueweijd").html(hehe[9]["sum(xuefen)"].slice(0,5));

    });


    $.post("/xjxt/gerenchengji?username="+ username +"",function(res){

        var hehe = JSON.parse(res);
        console.log(hehe);
        //动态的创建一个table，同时将后台获取的数据动态的填充到相应的单元格
        $("#diyixueqi").append("<tr id='first'>"+ "<td>" + "课程" +"</td>" + "<td>" + "课程号"+"</td>" +"<td>" + "学分" +"</td>"+ "<td>" +"课程性质" +"</td>"+ "<td>" +"正考" +"</td>"+ "<td>" +"补考" +"</td>"+ "<td>" +"绩点"+"</td>" +"</tr>");
        $.each(hehe, function (colIndex, col) {
            if(col.leixing == ["1"]) {
                var th;
                th+="<td>" + col.kecheng+"</td>" + "<td>" +col.kechenghao+"</td>" + "<td>" +col.xuefen+"</td>" + "<td>" +col.kechengxingzhi+"</td>" +"<td>" +col.zhengkao+"</td>" + "<td>" +col.bukao+"</td>" + "<td>" +col.jidian +"</td>";
                $("#diyixueqi").append("<tr>" + th + "</tr>");
            }

        });
    });

    $.post("/xjxt/quanxiaotongxuan?username="+ username +"",function(res){

        var hehe = JSON.parse(res);
        console.log(hehe);
        //动态的创建一个table，同时将后台获取的数据动态的填充到相应的单元格
        $("#tongxuan").append("<tr>"+ "<td>" + "学期" +"</td>" + "<td>" + "课程"+"</td>" +"<td>" + "课程号" +"</td>"+ "<td>" +"学分" +"</td>"+ "<td>" +"正考" +"</td>"+ "<td>" +"补考" +"</td>"+ "<td>" +"绩点"+"</td>" +"</tr>");
        $.each(hehe, function (colIndex, col) {
            if(col.leixing == ["2"]) {
                var th;
                th += "<td>" + col.shijian + "</td>" + "<td>" + col.kecheng + "</td>" + "<td>" + col.kechenghao + "</td>" + "<td>" + col.xuefen + "</td>" + "<td>" + col.zhengkao + "</td>" + "<td>" + col.bukao + "</td>" + "<td>" + col.jidian + "</td>";
                $("#tongxuan").append("<tr>" + th + "</tr>");
            }
        });
    });

    $.post("/xjxt/tiyukecheng?username="+ username +"",function(res){

        var hehe = JSON.parse(res);
        console.log(hehe);
        //动态的创建一个table，同时将后台获取的数据动态的填充到相应的单元格
        $("#tiyu").append("<tr>"+ "<td>" + "学期" +"</td>" + "<td>" + "课程"+"</td>" +"<td>" + "课程号" +"</td>"+ "<td>" +"学分" +"</td>"+ "<td>" +"正考" +"</td>"+ "<td>" +"补考" +"</td>"+ "<td>" +"绩点"+"</td>" +"</tr>");
        $.each(hehe, function (colIndex, col) {
            if(col.leixing == ["3"]) {
                var th;
                th += "<td>" + col.shijian + "</td>" + "<td>" + col.kecheng + "</td>" + "<td>" + col.kechenghao + "</td>" + "<td>" + col.xuefen + "</td>" + "<td>" + col.zhengkao + "</td>" + "<td>" + col.bukao + "</td>" + "<td>" + col.jidian + "</td>";
                $("#tiyu").append("<tr>" + th + "</tr>");
            }
        });
    });

    $.post("/xjxt/dengjikaoshi?username="+ username +"",function(res){

        var hehe = JSON.parse(res);
        console.log(hehe);
        //动态的创建一个table，同时将后台获取的数据动态的填充到相应的单元格
        $("#dengji").append("<tr>"+ "<td>" + "准考证号" +"</td>" + "<td>" + "考试场次"+"</td>" +"<td>" + "语言级别" +"</td>"+ "<td>" +"总分" +"</td>"+ "<td>" +"听力" +"</td>"+ "<td>" +"阅读" +"</td>"+ "<td>" +"写作"+"</td>" + "<td>" +"综合"+"</td>" +"</tr>");
        $.each(hehe, function (colIndex, col) {
            var th;
            th+="<td>" + col.zhunkaozheng+"</td>" + "<td>" +col.kaoshichangci+"</td>" + "<td>" +col.yuyanjibie+"</td>" + "<td>" +col.zongfen+"</td>" +"<td>" +col.tingli+"</td>" + "<td>" +col.yuedu+"</td>" + "<td>" +col.xiezuo +"</td>" + "<td>" +col.zonghe +"</td>";
            $("#dengji").append("<tr>" + th + "</tr>");
        });
    });


    $("input[type=text]").change(function () {
        var searchText = $(this).val();//获取输入的搜索内容
        if (searchText != "") {

            $("#diyixueqi tr:not('#first')").hide().filter(":contains('"+searchText+"')").show();
        }
        else {
            $("#diyixueqi tr").show();
        }
    })
    $("input[type=submit]").click(function () {
        $("searchText").change();
    })

});